﻿#include<stdio.h>
#include<stdlib.h>
struct BinaryTree
{
	char data;
	struct BinaryTree* lchild;    
	struct BinaryTree* rchild;    
};
struct BinaryTree* Creat()    
{
	char x;
	struct BinaryTree* tree;
	if (scanf("%c", &x))
	{
		if (x != '#')
		{
			tree = (struct BinaryTree*)malloc(sizeof(struct BinaryTree));
			tree->data = x;
			tree->lchild = Creat();     
			tree->rchild = Creat();     
		}
		else
			tree = NULL;
	}
	return tree;
}
void swap(struct BinaryTree* tree) 
{
	struct BinaryTree* temp;
	if (tree == NULL)
		return;
	temp = tree->lchild;
	tree->lchild = tree->rchild;
	tree->rchild = temp;

	swap(tree->lchild);     
	swap(tree->rchild);	    
}
void InOrder(struct BinaryTree* tree)  
{
	if (tree != NULL)
	{
		InOrder(tree->lchild);
		printf("%c", tree->data);
		InOrder(tree->rchild);
	}
}
int main()
{
	struct BinaryTree* tree;
	tree = Creat();
	InOrder(tree);
	swap(tree);
	printf("\n");
	InOrder(tree);
	return 0;
}